package com.wechat.page.chat.message.msg;

import com.swak.entity.YesNo;
import com.swak.fx.support.ui.UILifecycle;
import com.wechat.dto.MessageDTO;

import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;

public abstract class AbstractMsgComp extends AnchorPane implements MsgComp, UILifecycle {

	protected final MessageDTO message;
	protected boolean sender = false;
	protected Pane arrows;

	protected AbstractMsgComp(MessageDTO message) {
		this.sender = message.getIsSender() == YesNo.Yes.getType() ? true : false;
		this.message = message;
		this.arrows = new Pane();
	}

	@Override
	public void initializeParts() {
		Node content = this.getContentNode();
		this.arrows.setPrefWidth(10);
		this.arrows.setPrefHeight(10);
		this.arrows.setRotate(45);
		this.getChildren().addAll(arrows, content);

		if (!this.sender) {
			AnchorPane.setLeftAnchor(arrows, 0.0);
			AnchorPane.setTopAnchor(arrows, 12.0);
			AnchorPane.setTopAnchor(content, 0.0);
			AnchorPane.setLeftAnchor(content, 4.0);
			AnchorPane.setRightAnchor(content, 0.0);
		} else {
			AnchorPane.setRightAnchor(arrows, 0.0);
			AnchorPane.setTopAnchor(arrows, 12.0);
			AnchorPane.setTopAnchor(content, 0.0);
			AnchorPane.setRightAnchor(content, 4.0);
			AnchorPane.setLeftAnchor(content, 0.0);
		}
	}

	protected abstract Node getContentNode();
}
